package BookSystem;

import java.util.ArrayList;
import java.util.Collection;

public class Library {
    private Collection<Book> books;

    public Library() {
        this.books = new ArrayList<>();
    }


    public void addBook(Book book){
        books.add(book);
        System.out.println(book+"添加图书成功");
    }


    public void removeBook(Book book){
        if (books.remove(book)) {
            System.out.println(book + "删除图书成功");
        }else{
            System.out.println(book + "图书不存在,删除失败!");
        }
    }


    public Book FindBookByName(String name){
        for (Book book : books) {
            if (book.getName().equals(name)) {
                return book;
            }
        }
        return null;
    }


    public void ShowAllBooks(){
        if (books.isEmpty()) {
            System.out.println("图书馆中没有图书!");
        } else {
            System.out.println("图书馆中的图书:");
            for (Book book : books) {
                System.out.println(book);
            }
        }
    }
}
